<meta charset="utf-8"/>
<div class="row">
  <div class="col-xs-12">
    <div class="row">
      <div class="col-xs-12">
        <div class="clearfix">
          <table class="no-border" style="display:inline">
            <tr permission='allUser_btn_listData' style="display:none">
              <td style="padding: 0px 6px;">
                账号
              </td>
              <td>
                <div class="input-group">
                  <input type="text" id="key_user_name" class="form-control search-query" placeholder="登录账号" style="width:140px"/>
                </div>
              </td>
              <td class="areaSelectText" style="padding: 0px 6px;">
                区域
              </td>
              <td class="areaSelectText">
                <div class="input-group">
                  <div id="divArea"></div>
                </div>
              </td>
              <td class="hidden-480" style="padding: 0px 6px;">
                身份
              </td>
              <td>
                <span class="input-group-btn">
                  <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle col-sm-12" style="margin-left:0.01em">
                    <span id="searchDropdownType">全部</span>
                    <i class="ace-icon fa fa-angle-down"></i>
                  </button>
                  <ul class="dropdown-menu col-sm-12" style="margin-left:-1px;width:71px;min-width:71px;">
                    <li>
                      <a href="javascript:winFn.dropdown('#key_type','','#searchDropdownType','全部');">全部</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_type','1','#searchDropdownType','普通');">普通</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_type','2','#searchDropdownType','律师');">律师</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_type','3','#searchDropdownType','企业');">企业</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_type','4','#searchDropdownType','未知');">未知</a>
                    </li>
                  </ul>
                  <input id="key_type" type="hidden"/>
                </span>
              </td>
              <td class="hidden-480" style="padding: 0px 6px;">
                合作伙伴
              </td>
              <td>
                <span class="input-group-btn">
                  <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle col-sm-12" style="margin-left:0.01em">
                    <span id="searchDropdownpartner">全部</span>
                    <i class="ace-icon fa fa-angle-down"></i>
                  </button>
                  <ul class="dropdown-menu col-sm-12" style="margin-left:-1px;width:71px;min-width:71px;">
                    <li>
                      <a href="javascript:winFn.dropdown('#key_partner','','#searchDropdownpartner','全部');">全部</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_partner','0','#searchDropdownpartner','是');">是</a>
                    </li>
                  </ul>
                  <input id="key_partner" type="hidden"/>
                </span>
              </td>
              <!--<td class="hidden-480" style="padding: 0px 6px;">
                领域
              </td>
              <td>
                <div class="input-group">
                  <span class="input-group-btn">
                    <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle col-sm-12" style="margin-left:0.01em">
                      <span id="dropdownLabelkey_domain_id">全部领域</span>
                      <i class="ace-icon fa fa-angle-down"></i>
                    </button>
                    <ul class="dropdown-menu col-sm-12" style="margin-left:-1px;width:99px;min-width:99px;" id="dropdownOptionskey_domain_id"></ul>
                    <input id="key_domain_id" type="hidden"/>
                  </span>
                </div>
              </td>-->
              <td class="hidden-480" style="padding: 0px 6px;">
                状态
              </td>
              <td>
                <span class="input-group-btn">
                  <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle col-sm-12" style="margin-left:0.01em">
                    <span id="searchDropdownenabled">全部</span>
                    <i class="ace-icon fa fa-angle-down"></i>
                  </button>
                  <ul class="dropdown-menu col-sm-12" style="margin-left:-1px;width:71px;min-width:71px;">
                    <li>
                      <a href="javascript:winFn.dropdown('#key_enabled','','#searchDropdownenabled','全部');">全部</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_enabled','0','#searchDropdownenabled','正常');">正常</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_enabled','1','#searchDropdownenabled','冻结');">冻结</a>
                    </li>
                  </ul>
                  <input id="key_enabled" type="hidden"/>
                </span>
              </td>
              <td>
                <div class="input-group">
                  <span class="input-group-btn">
                    <button type="button" class="btn btn-inverse btn-white" id="btnSearch" permission='allUser_btn_listData' style="display:none">
                      <span class="ace-icon fa fa-search bigger-110"></span>
                      搜索
                    </button>
                  </span>
                </div>
              </td>
              <td>
                <div class="input-group">
                  <span class="input-group-btn">
                    <button type="button" class="btn btn-inverse btn-white" title="导出当前查询数据" id="btnExport" permission='allUser_btn_export' style="display:none">
                      <span class="fa fa-upload red2"></span>
                      导出
                    </button>
                  </span>
                </div>
              </td>
              <td>
                <div class="input-group">
                  <span class="input-group-btn">
                    <button type="button" class="btn btn-inverse btn-white" title="导出当前查询数据" id="btnSendSms" permission='allUser_btn_sendSms' style="display:none">
                      <span class="fa fa-envelope-o green"></span>
                      短信
                    </button>
                  </span>
                </div>
              </td>
            </tr>
          </table>
          <div class="hidden-480 pull-right tableTools-container" permission='allUser_btn_listData' style="display:none"></div>
        </div>
        <table id="tableListAllUser" class="table table-striped table-bordered table-hover"></table>
      </div>
    </div>
  </div>
</div>
<div id="div_sys_user_edit" style="display:none;padding-top:2px;margin-bottom:-20px;">
  <form class="form-horizontal" id="form_sys_user_edit" role="form">
    <label class="col-sm-3 control-label no-padding-right" for="user_name"><div class="hr-4"></div>登录账号</label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
    <input type="text" id="user_name" placeholder="登录账号" class="form-control" maxlength="64"/>
    </div>
  </form>
</div>
<div id="divKeyColumns" style="display:none;padding:1px 0px;"></div>
<input type="hidden" id="sys_user_edit_keyId"/>
<div style="display:none;">
  <input type="hidden" id="allUser_btn_listData"/>
  <input type="hidden" id="allUser_btn_export"/>
  <input type="hidden" id="allUser_btn_sendSms"/>
  <input type="hidden" id="allUser_btn_listSearch"/>
</div>
<div id="div_bind_area" style="display:none;padding:2px 2px 2px 0px">
  <div class="input-group">
    <input type="text" id="searchValue" class="form-control search-query" placeholder="关键字,支持模糊查询"/>
    <span class="input-group-btn">
      <button type="button" class="btn btn-inverse btn-white" id="valueSearch">
        <span class="ace-icon fa fa-search bigger-110"></span>
        查询
      </button>
    </span>
  </div>
  <table id="listArea" class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
      <td>选项</td>
      <td>模板属性</td>
    </tr>
    </thead>
    <tbody>
    <tr>
      <td colspan="2" style="height:37px;text-align:center;">正在加载……</td>
    </tr>
    </tbody>
  </table>
</div>
<script type="text/javascript">
  var scripts = [null, null];
  $('.page-content-area').ace_ajax('loadScripts', scripts, function(){
    var tableDom = '#tableListAllUser';
    $(function(){
      var urlRoute = '/allUser/';/*请求controller层的url*/
      var getList = urlRoute + 'listData';/*获取数据列表*/
      var urlExportExcel = urlRoute + 'exportExcel';/*导出发送短信用户*/
      var urlAddSendSms = urlRoute + 'addSendSms';/*批量发送短信,以复选框发送|以搜索发送*/
      var urlDomainList = urlRoute + 'getDomainList';/*获取擅长领域列表*/
      var urlQueryArea = urlRoute + 'queryArea';/*获取区域数据*/
      var urlGetListSearch = urlRoute + 'getListSearch';/*获取模板数据*/
      var thisTable = pageDataTable.initDataTable({
        tableDom : tableDom,
        sAjaxSource : getList,
        fnServerParams : function(params){
          params.push({"name": "user_name","value": $("#key_user_name").val()},{"name": "enabled", "value": $("#key_enabled").val()},{"name": "type", "value": $("#key_type").val()},{"name": "partner","value": $("#key_partner").val()},{"name": "domain_id","value": $("#key_domain_id").val()});
          var province_id = $('#divArea .clsProvince').val();
          var city_id = $('#divArea .clsCity').val();
          var county_id = $('#divArea .clsCounty').val();
          if(province_id){
            params.push({"name": "province_id","value": province_id});
          }
          if(city_id){
            params.push({"name": "city_id","value": city_id});
          }
          if(county_id){
            params.push({"name": "county_id","value": county_id});
          }
        },
        aoColumns : [
          {
            bSortable : false,
              mData : "user_name",
              sWidth : "38px",
              sClass : "center",
              visible : true,/*若不用到时设为false即可,请勿删除否则有bug*/
              sTitle : '<label title="全选|不选"><input type="checkbox" class="ace" /><span class="lbl"></span></label>'
          },
          {
            mData : "user_name",
            sTitle : "登录账号"
          },
          {
            mData : "name_flag",
            bSortable : false,
            sTitle : "姓名|名称",
            render : function(value,type,row,meta){
              if(row.enterprise_name){
                return row.enterprise_name;
              }
              if(row.lawyer_name){
                return row.lawyer_name;
              }
              return "";
            }
          },
          {
            mData : "add_date",
            sTitle : "注册日期"
          },
          {
            mData : "enabled",
            sTitle : "账号状态",
            render : function(value,type,row,meta){
              if(value === 0){
                return '正常';
              }else if(value === 1){
                return '<span style="color:#d00">冻结</span>';
              }else{
                return "";
              }
            }
          },
          {
            mData : "identity",
            bSortable : false,
            sTitle : "账号身份",
            render : function(value,type,row,meta){
              var pr = (row.partner != null && row.partner != '') ? ",合作伙伴" : "";
              if(row.lawyer){
                return '<span style="color:#30ce40">律师身份'+pr+'</span>';
              }
              if(row.enterprise){
                return '<span style="color:#1bc6fa">企业身份'+pr+'</span>';
              }
              return "未知身份"+pr;
            }
          },
          {
            mData : "_address_",
            bSortable : false,
            sTitle : "注册地址|认证地址",
            render : function(value,type,row,meta){
              if(row.addr_lawyer){
                return row.addr_lawyer;
              }
              if(row.addr_enterprise){
                return row.addr_enterprise;
              }
              if(row.address){
                return row.address;
              }
              return "";
            }
          }
        ],
        columnDefs : [
          {
            targets : 0,//指定的列
            render : function(value, type, row, meta){
              return '<label title="选择|取消"><input type="checkbox" name="user_name" value="' + value + '" style="cursor:pointer;text-decoration:none;outline:none;"/><span class="lbl"></span></label>';
            }
          },
          {
          visible : false,//列的隐藏显示
          targets : []//指定列
          }
        ]
      });
      pageDataTable.buttons(thisTable);
      pageDataTable.action(thisTable);
      pageDataTable.select(thisTable, tableDom);
      pageDataTable.tooltip();
      var thisJquery = $(tableDom).dataTable();
      thisPage = {
        init: function(){
          this.addEvent();
          this.initDom();
        },
        initDom: function(){
          //this.createDropdown();
          //这个'0'不能写成0,否则有问题
          optsArea.initArea(urlQueryArea,'0','#divArea',"{\"clsProvince\":\"选择省市\",\"clsCity\":\"选择地州市\",\"clsCounty\":\"请选择区|县\",\"start\":\"clsProvince\",\"end\":\"clsTowns\"}");
        },
        createDropdown: function(){
          layerFn.ajaxGet(urlDomainList, {}, function(data){
            if(data.code === AppKey.code.code200){
              winFn.initDropdown(data.data,'#dropdownOptionskey_domain_id','#key_domain_id','#dropdownLabelkey_domain_id','全部领域');
            }
          });
        },
        addEvent: function(){
          this.btnEvent();
        },
        btnEvent: function(){
          $(tableDom + ' tbody').on('dblclick','tr', function(){
            if(verifyFn.inputRequired('#allUser_row_edit')){
              return;
            }
            thisPage.trDblclick(thisTable.row(this).data());
          });
          //搜索按钮
          $('#btnSearch').on('click', function(){
            thisPage.search();
          });
          //导出
          $('#btnExport').on('click',function(){
            if(verifyFn.inputRequired('#allUser_btn_export')){
              layerFn.alert('没有导出操作权限',AppKey.code.code199);
              return;
            }
            layerFn.confirm('您确定要导出当前条件的数据吗?',function(){
              thisPage.exportExcel();
            });
          });
          $('#btnSendSms').on('click', function(){
            if(verifyFn.inputRequired('#allUser_btn_sendSms')){
              layerFn.alert('没有操作权限',AppKey.code.code199);
              return;
            }
            thisPage.openSearchDialog();
          });
          //按钮组-自定义显示列
          $('#iconColumn').parent().parent().on('click', function(){
            pageDataTable.columnCustom(thisTable, tableDom,'#divKeyColumns');
          });
          //按钮组-搜索
          $('#iconRefresh').parent().parent().on('click', function(){
            thisPage.search();
          });
          /*对话框的搜索查询按钮*/
          $('#valueSearch').on('click',function(){
            var value = winFn.getDomValue('#searchValue');
            thisPage.getListSite(value);
          });
        },
        /*批量发送*/
        sends: function(code,variate,indexLayero){
          var kids = '';
          var index = 0;
          $(tableDom + ' tbody input:checked').each(function(){
            index++;
            var value = this.value;
            if(value != null && value != ''){
              if(kids.length > 0) kids += ",";
              kids += value;
            }
          });
          if(index > 0){//优先选择复选框的数据
            layerFn.confirm('将要以所选模板发送短信给[' + index + ']个用户,确定要继续吗?', function(){
              layerFn.closeIndex(indexLayero);
              layerFn.submit(urlAddSendSms,{kids:kids,code:code,variate:variate},function(data){
                layerFn.handleResult(data.msg,data.code);
              });
            });
          }else{
            layerFn.confirm('确定要以所选模板用当前查询的全部数据发送短信吗?', function(){
              layerFn.closeIndex(indexLayero);
              var params = [];
              params.push({"name": "user_name","value": $("#key_user_name").val()},{"name": "enabled", "value": $("#key_enabled").val()},{"name": "type", "value": $("#key_type").val()},{"name": "partner","value": $("#key_partner").val()},{"name": "domain_id","value": $("#key_domain_id").val()});
              var province_id = $('#divArea .clsProvince').val();
              var city_id = $('#divArea .clsCity').val();
              var county_id = $('#divArea .clsCounty').val();
              if(province_id){
                params.push({"name": "province_id","value": province_id});
              }
              if(city_id){
                params.push({"name": "city_id","value": city_id});
              }
              if(county_id){
                params.push({"name": "county_id","value": county_id});
              }
              params.push({"name": "code","value": code});
              params.push({"name": "variate","value": variate});
              layerFn.submit(urlAddSendSms,params,function(data){
                layerFn.handleResult(data.msg,data.code);
              });
            });
          }
        },
        trDblclick: function(data){},
        exportExcel : function(){
          var province_id = $('#divArea .clsProvince').val();
          var city_id = $('#divArea .clsCity').val();
          var county_id = $('#divArea .clsCounty').val();
          var url = urlExportExcel+'?&user_name='+$("#key_user_name").val();
          if(province_id != undefined && province_id != ''){
            url = url+'&province_id='+province_id;
          }
          if(city_id != undefined && city_id != ''){
            url = url+'&city_id='+city_id;
          }
          if(county_id != undefined && county_id != ''){
            url = url+'&county_id='+county_id;
          }
          url = url+'&enabled='+$("#key_enabled").val()+
            '&type='+$("#key_type").val()+
            '&partner='+$("#key_partner").val()+
            '&domain_id='+$("#key_domain_id").val()
          layerFn.handleTop('请耐心等待,处理完成将会自动下载!',AppKey.code.code200);
          winFn.getPageHashToken(url);
        },
        search: function(){
          if(verifyFn.inputCheck('#allUser_btn_listData','没有操作权限')) return;
          $(tableDom + '_wrapper table input[type=checkbox]').prop('checked', false);
          thisTable.draw();
        },
        resetForm: function(){
          winFn.clearFormData('#form_sys_user_edit');
        },
        /*打开弹出搜索框*/
        openSearchDialog : function(){
          $('#searchValue').val('');
          layerFn.addOrEdit('选择短信模板','#div_bind_area',['550px','450px'],function(indexLayero,layero){
            var values = '';
            var names = '';
            var index = 0;
            $("input[name='valueKid']:checked").each(function(){
              index++;
              var v = $(this).val();
              var name = $(this).attr('alt');
              if(values.length > 0){
                values = values + ',' + v;
                names = names + ',' + name;
              }else{
                values = v;
                names = name;
              }
            });
            if(index == 0){
              layerFn.alert('请选择一个短信模板',AppKey.code.code199);
              return;
            }
            if(index > 1){
              layerFn.alert('仅能选择一个短信模板',AppKey.code.code199);
              return;
            }
            thisPage.sends(values,names,indexLayero);
          },'<span style="color:#f84009;">重置</span>',function(){
            $('#searchValue').val('');
            $("input[name='valueKid']:checked").each(function(){
              var v = $(this).attr("checked",false);
            });
          });
          thisPage.getListSite();
        },
        /*查询数据*/
        getListSite : function(value){
          var params = {};
          if(value != null && value.length > 0){
            params = {
              value : value
            };
          }
          layerFn.queryGetHintResult(urlGetListSearch,params,function(data){
            thisPage.renderArea(data);
          });
        },
        /*渲染页面*/
        renderArea : function(data){
          var html = '';
          if(AppKey.code.code200 == data.code){
            data = data.data;
            for(var i=0;i<data.length;i++){
              var obj = data[i];
              html += '<tr>';
              html += '<td style="width:46px;text-align:center;"><label><input name="valueKid" value="'+obj.template_code+'" alt="'+obj.phone_variate+'" type="checkbox" class="ace"/><span class="lbl"></span></label></td>';
              html += '<td>'+obj.template_code+'，'+obj.template_name+'</td>';
              html += '</tr>';
            }
          }else if(AppKey.code.code201 == data.code){
            html = '<td colspan="2" style="height:37px;text-align:center;">没有查到数据,请换个关键字试试</td>';
          }else{
            html = '<td colspan="2" style="height:37px;text-align:center;">'+data.msg+'</td>';
          }
          $('#listArea tbody').empty().html(html);
        },
        complete: function(data, index, search){
          try{
            if(index){
              layerFn.closeIndex(index);
            }
            if(search){
              thisPage.search();
            }
            if(data){
              layerFn.handleResult(data.msg, data.code);
            }
          }catch(e){}
        }
      };
      thisPage.init();
    });
  });
</script>